<?

/**
* local collection functions of tocmenu_31
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLFetchers
*
*/

/**
* @package CLFetchers
*
*/
class CLFetchers{

  /**
   * source issued DP detail
   *
   * @param Database  $Db
   * @param string    $refId
   * @param string    $sourceId
   * @param string    $srcDb
   * @param array     $resSrcDp
   */
  function fetchSourceDp(&$Db,
                         &$refId,
                         &$sourceId,
                          $srcDb,
                         &$resSrcDp){

    $query	= "SELECT *
               FROM ".$srcDb."
               WHERE	REFERENCE='".$refId."'
                      AND SOURCE='".$sourceId."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $resSrcDp);
  }

  /**
   * DP amount by supplier
   *
   * @param Database  $Db
   * @param string    $condt        REFERENCE, SOURCE, JOB_ID, etc
   * @param string    $source       jobId, refid , or else
   * @param string    $srcDb
   * @param integer   $nIssued
   * @param array     $resIssued
   */
  function dpAmountBySupplier(&$Db,
                               $condt,
                               $source,
                               $srcDb,
                              &$nIssued,
                              &$resIssued){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  ".$condt."='".$source."' ";

    $Db->execFetchQuery($query,
                        $nIssued,
                        $resIssued);
  }

  /**
   * Dp issued for this supplier within
   * this periode
   *
   * @param Database  $Db
   * @param string    $suppCode
   * @param string    $srcDpOutRefId
   * @param string    $type
   * @param string    $periode
   * @param string    $srcDb
   * @param integer   $nIssued
   * @param array     $issued
   */
  function fetchDpIssued(&$Db,
                         &$suppCode,
                         &$periode,
                         &$type,
                          $srcDb,
                         &$nIssued,
                         &$issued){

    $issued = array("REFERENCE" => array(),
                    "SOURCE"    => array(),
                    "AMOUNT"    => array(),
                    "TR_DATE"   => array(),
                    "DUE_DATE"  => array());

    switch($type){

      case _CASH_BANK_IN:

        $condt = " AND TX_TYPE NOT IN ("._CASH_OUT.","._BANK_OUT.","._GIRO_OUT.")";
        break;

      case _CASH_BANK_OUT:

        $condt = " AND TX_TYPE NOT IN ("._CASH_IN.","._BANK_IN.","._GIRO_IN.")";
        break;

      default:
        $condt = " ";
    }

    $query  = "SELECT DISTINCT H.REFERENCE
               FROM ".$srcDb." H
               WHERE  H.PERIODE=".$periode."
                      AND H.REFERENCE<>H.SOURCE
                      AND SUPPLIER_CODE='".$suppCode."'
                      ".$condt." ";

    $Db->execFetchQuery($query,
                        $nJid,
                        $resJid);

    /**
     * foreach source JID
     * extract the amount
     */
    for($iJid = 0; $iJid < $nJid ; $iJid++){

      /**
       * fetch the amount of tx which used the dp
       */
      $this->dpAmountBySupplier($Db,
                                "REFERENCE",
                                $resJid["REFERENCE"][$iJid],
                                $srcDb,
                                $nIssued,
                                $resIssued);

      array_push($issued["REFERENCE"], $resJid["REFERENCE"][$iJid]);

      array_push($issued["SOURCE"], $resIssued["SOURCE"][0]);

      array_push($issued["AMOUNT"], $resIssued["AMOUNT"][0]);

      array_push($issued["TR_DATE"], $resIssued["TR_DATE"][0]);

      array_push($issued["DUE_DATE"], $resIssued["DUE_DATE"][0]);
    }

    $nIssued = sizeof($issued["REFERENCE"]);
  }

  /**
   * Sub detail of DP
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nDetail
   * @param array     $lstDetail
   */
  function fetchSubDp(&$Db,
                       $jobId,
                       $srcDb,
                      &$nDetail,
                      &$lstDetail){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  JOB_ID='".$jobId."'
               ORDER BY NO ASC";

    $Db->execFetchQuery($query,
                        $nDetail,
                        $lstDetail);
  }

  /**
   * Detail of DP
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nDetail
   * @param array     $lstDetail
   */
  function fetchDtlDp(&$Db,
                       $jobId,
                       $srcDb,
                      &$nDetail,
                      &$lstDetail){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nDetail,
                        $lstDetail);
  }

  /**
   * last entry number of
   * mutation Cash bank detail number
   *
   * @param Database  $Db
   * @param string    $sysPeriode
   * @param string    $srcDb
   * @param integer   $mutCbDtlNo
   */
  function fetchLastMutCbDtlNo(&$Db,
                                $sysPeriode,
                                $srcDb,
                               &$mutCbDtlNo){

    $sysPeriode = " TO_DATE('".$sysPeriode."','mm-YYYY')";

    $query	= "SELECT NO
               FROM ".$srcDb."
               WHERE	PERIODE=".$sysPeriode."
               ORDER BY NO desc";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    if($nrows > 0){

      $mutCbDtlNo = $result["NO"][0] + 1;
    }else{

      $mutCbDtlNo = 1;
    }
  }

  /**
   * cash bank type
   * CASH, BANK or GIRO
   *
   * @param Database  $Db
   * @param string    $cbCode
   * @param string    $srcDb
   * @param string    $cbTxType
   */
  function fetchCbTxType(&$Db,
                         &$cbCode,
                          $srcDb,
                         &$cbTxType){

    $query	= "SELECT *
               FROM ".$srcDb."
               WHERE	C_B_CODE='".$cbCode."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $cbTxType = $result["C_B_TYPE"][0];
  }

/**
   * last number of mutation
   *
   * @param Database  $Db
   * @param string    $condt     additional condition
   * @param string    $refId
   * @param string    $srcDb
   * @param integer   $subDtlNo
   */
  function fetchLastMutationNo2(&$Db,
                                 $condt,
                                &$jobId,
                                 $srcDb,
                                &$subDtlNo){

    $query  = "SELECT NO
               FROM ".$srcDb."
               WHERE  ".$condt."='".$jobId."'
               ORDER BY NO DESC  ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    if($nrows > 0){

      $subDtlNo = $result["NO"][0] + 1;
    }else{

      $subDtlNo = 1;
    }
  }

  /**
   * last number of mutation
   *
   * @param Database  $Db
   * @param string    $refId
   * @param string    $srcDb
   * @param integer   $subDtlNo
   */
  function fetchLastMutationNo(&$Db,
                               &$refId,
                                $srcDb,
                               &$subDtlNo){

    $query	= "SELECT NO
               FROM ".$srcDb."
               WHERE  REFERENCE='".$refId."'
               ORDER BY NO DESC	 ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    if($nrows > 0){

      $subDtlNo = $result["NO"][0] + 1;
    }else{

      $subDtlNo = 1;
    }
  }

  /**
   * sub detail
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param Composer  $SourceDb
   * @param integer   $nSubDetail
   * @param array     $lstSubDetail
   */
  function fetchLstDataSubDetail(&$Db,
                                 &$jobId,
                                 &$SourceDb,
                                 &$nSubDetail,
                                 &$lstSubDetail){

    $query	= "SELECT S.*,
                      A.GL_ACC_NAME,
                      O.GL_SUB_ACC_NAME
               FROM ".$SourceDb->fetchValue("srcDbSubDtl")."      S,
                    ".$SourceDb->fetchValue("srcDbMstGlAcc")."    A,
                    ".$SourceDb->fetchValue("srcDbMstGlOptAcc")." O
               WHERE	S.JOB_ID='".$jobId."'
                      AND A.GL_ACC_CODE=S.GL_ACC
                      AND O.GL_SUB_ACC_CODE=S.GL_SUB_ACC
               ORDER BY S.NO ASC";

    $Db->execFetchQuery($query,
                        $nSubDetail,
                        $lstSubDetail);
  }

  /**
   * data detail
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nDetail
   * @param array     $lstDetail
   */
  function fetchLstDataDetail(&$Db,
                              &$jobId,
                               $srcDb,
                              &$nDetail,
                              &$lstDetail){

    $query	= "SELECT *
               FROM ".$srcDb."
               WHERE	JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nDetail,
                        $lstDetail);
  }

  /**
   * data header
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param Composer  $SourceDb
   * @param integer   $nHeader
   * @param array     $lstHeader
   */
  function fetchLstDataHeader(&$Db,
                              &$jobId,
                              &$SourceDb,
                              &$nHeader,
                              &$lstHeader){

    $query	= "SELECT H.*,
                      C.C_B_NAME,
                      T.CASH_BANK_TX_NAME
               FROM ".$SourceDb->fetchValue("srcDbHdr")."   H,
                    ".$SourceDb->fetchValue("srcDbMstCb")." C,
                    ".$SourceDb->fetchValue("srcDbCbTx")."  T
               WHERE	H.JOB_ID='".$jobId."'
                      AND C.C_B_CODE=H.C_B_CODE
                      AND T.CASH_BANK_TX_CODE=H.TYPE";

    $Db->execFetchQuery($query,
                        $nHeader,
                        $lstHeader);

    if($lstHeader["IN_OUT"][$iRow] == _CASH_BANK_IN){

      $query  = "SELECT CUSTOMER_NAME as SUPPLIER_CUSTOMER_NAME
                 FROM ".$SourceDb->fetchValue("srcDbCustomer")."
                 WHERE  CUSTOMER_CODE='".$lstHeader["SUPPLIER_CUSTOMER"][0]."' ";


    }else{

      $query  = "SELECT SUPPLIER_NAME as SUPPLIER_CUSTOMER_NAME
                 FROM ".$SourceDb->fetchValue("srcDbSupplier")."
                 WHERE  SUPPLIER_CODE='".$lstHeader["SUPPLIER_CUSTOMER"][0]."' ";
    }

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    if($nrows > 0){

      $lstHeader["SUPPLIER_CUSTOMER_NAME"][0] = $result["SUPPLIER_CUSTOMER_NAME"][0];
    }else{

      Misc::usrDieJs("Error: Supplier or Customer doesn't exists");
    }
  }

  /**
  * fetch the list of valid transactions
  *
  * @param  string    $Db
  * @param  string    $condt      the condition
  * @param  Composer  $SourceDb
  * @param  string    $lstResult
  *
  */
  function fetchLstTransaction(&$Db,
                                $condt,
                               &$SourceDb,
                               &$nResult,
                               &$lstResult){

    $query  = "SELECT H.*,
                      C.C_B_NAME,
                      T.CASH_BANK_TX_NAME
               FROM ".$SourceDb->fetchValue("srcDbHdr")."   H,
                    ".$SourceDb->fetchValue("srcDbMstCb")." C,
                    ".$SourceDb->fetchValue("srcDbCbTx")."  T
               ".$condt."
                      AND C.C_B_CODE=H.C_B_CODE
                      AND T.CASH_BANK_TX_CODE=H.TYPE
               ORDER BY H.TR_DATE DESC ";

    $Db->execFetchQuery($query,
                        $nResult,
                        $lstResult);

    for($iRow = 0; $iRow < $nResult ; $iRow++){

      if($lstResult["IN_OUT"][$iRow] == _CASH_BANK_IN){

        $query  = "SELECT CUSTOMER_NAME as SUPPLIER_CUSTOMER_NAME
                   FROM ".$SourceDb->fetchValue("srcDbCustomer")."
                   WHERE  CUSTOMER_CODE='".$lstResult["SUPPLIER_CUSTOMER"][$iRow]."' ";


      }else{

        $query  = "SELECT SUPPLIER_NAME as SUPPLIER_CUSTOMER_NAME
                   FROM ".$SourceDb->fetchValue("srcDbSupplier")."
                   WHERE  SUPPLIER_CODE='".$lstResult["SUPPLIER_CUSTOMER"][$iRow]."' ";
      }

      $Db->execFetchQuery($query,
                          $nrows,
                          $result);

      $lstResult["SUPPLIER_CUSTOMER_NAME"][$iRow] = $result["SUPPLIER_CUSTOMER_NAME"][0];
    }
  }

  /**
   * GL Sub Account Code by Name
   *
   * @param Database  $Db
   * @param string    $glAccCode
   * @param string    $glSubAccName
   * @param Composer  $SourceDb
   * @param string    $glSubAccCode
   */
  function fetchGlSubAccCode(&$Db,
                             &$glAccCode,
                             &$glSubAccName,
                             &$SourceDb,
                             &$glSubAccCode){

    $query  = "SELECT S.GL_SUB_ACC_CODE
               FROM ".$SourceDb->fetchValue("srcDbGlSubAcc")."     S,
                    ".$SourceDb->fetchValue("srcDbGlSubAccOpt")."  O
               WHERE  O.GL_SUB_ACC_NAME='".$glSubAccName."'
                      AND S.GL_ACC_CODE='".$glAccCode."'
                      AND S.GL_SUB_ACC_CODE=O.GL_SUB_ACC_CODE";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $glSubAccCode = $result["GL_SUB_ACC_CODE"][0];
  }

  /**
   * list of GL Sub Account
   *
   * @param Database  $Db
   * @param string    $glAccCode
   * @param Composer  $SourceDb
   * @param integer   $nGlSubAcc
   * @param array     $lstGlSubAcc
   */
  function fetchLstGlSubAcc(&$Db,
                            &$glAccCode,
                            &$SourceDb,
                            &$nGlSubAcc,
                            &$lstGlSubAcc){

    $query  = "SELECT O.GL_SUB_ACC_NAME
               FROM ".$SourceDb->fetchValue("srcDbGlSubAcc")."     S,
                    ".$SourceDb->fetchValue("srcDbGlSubAccOpt")."  O
               WHERE  S.GL_ACC_CODE='".$glAccCode."'
                      AND O.GL_SUB_ACC_CODE=S.GL_SUB_ACC_CODE
               ORDER BY O.GL_SUB_ACC_NAME ASC";

    $Db->execFetchQuery($query,
                        $nGlSubAcc,
                        $lstGlSubAcc);
  }

  /**
   * GL Account Code by Name
   *
   * @param Database  $Db
   * @param string    $glAccName
   * @param string    $srcDb
   * @param string    $glAccCode
   */
  function fetchGlAccCode(&$Db,
                          &$glAccName,
                           $srcDb,
                          &$glAccCode){

    $query	= "SELECT GL_ACC_CODE
               FROM ".$srcDb."
               WHERE	GL_ACC_NAME='".$glAccName."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $glAccCode = $result["GL_ACC_CODE"][0];
  }

  /**
   * list of GL account
   *
   * @param Database  $Db
   * @param string    $srcDb
   * @param integer   $nGlAcc
   * @param array     $lstGlAcc
   */
  function fetchLstGlAcc(&$Db,
                          $srcDb,
                         &$nGlAcc,
                         &$lstGlAcc){

    $query	= "SELECT GL_ACC_NAME
               FROM ".$srcDb."
               ORDER BY GL_ACC_NAME ASC";

    $Db->execFetchQuery($query,
                        $nGlAcc,
                        $lstGlAcc);
  }

  /**
   * cash bank name by code
   *
   * @param Database  $Db
   * @param string    $cbCode
   * @param string    $srcDb
   * @param array     $cbName
   */
  function fetchCbName(&$Db,
                       &$cbCode,
                        $srcDb,
                       &$cbName){

    $query	= "SELECT C_B_NAME
               FROM ".$srcDb."
               WHERE	C_B_CODE='".$cbCode."' ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $result);

    $cbName = $result["C_B_NAME"][0];
  }

  /**
   * list of cash bank code
   *
   * @param Database  $Db
   * @param string    $srcDb
   * @param integer   $nCbCode
   * @param array     $lstCbCode
   */
  function fetchLstCbCode(&$Db,
                           $srcDb,
                          &$nCbCode,
                          &$lstCbCode){

    $query	= "SELECT *
               FROM ".$srcDb."
               ORDER BY C_B_CODE ASC";

    $Db->execFetchQuery($query,
                        $nCbCode,
                        $lstCbCode);
  }

  /**
   * sub invoice
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nData
   * @param array     $lstData
   */
  function fetchSubInvoice(&$Db,
                           &$jobId,
                            $srcDb,
                           &$nData,
                           &$lstData){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  JOB_ID='".$jobId."'
               ORDER BY NO ASC";

    $Db->execFetchQuery($query,
                        $nData,
                        $lstData);
  }

  /**
   * dtl invoice
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nData
   * @param array     $lstData
   */
  function fetchDtlInvoice(&$Db,
                           &$jobId,
                            $srcDb,
                           &$nData,
                           &$lstData){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nData,
                        $lstData);
  }

  /**
   * temporary sub invoice
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nData
   * @param array     $lstData
   */
  function fetchTmpSubInvoice(&$Db,
                              &$jobId,
                               $srcDb,
                              &$nData,
                              &$lstData){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  JOB_ID='".$jobId."'
               ORDER BY NO ASC";

    $Db->execFetchQuery($query,
                        $nData,
                        $lstData);
  }

  /**
   * temporary DP detail
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nData
   * @param array     $lstData
   */
  function fetchTmpDtlDp(&$Db,
                         &$jobId,
                          $srcDb,
                         &$nData,
                         &$lstData){

    $query	= "SELECT  *
               FROM ".$srcDb."
               WHERE	 JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nData,
                        $lstData);
  }

  /**
   * temporary dtl invoice
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $srcDb
   * @param integer   $nData
   * @param array     $lstData
   */
  function fetchTmpDtlInvoice(&$Db,
                              &$jobId,
                               $srcDb,
                              &$nData,
                              &$lstData){

    $query	= "SELECT *
               FROM ".$srcDb."
               WHERE	JOB_ID='".$jobId."' ";

    $Db->execFetchQuery($query,
                        $nData,
                        $lstData);
  }

  /**
   * source (Pch/Sls) header details
   *
   * @param Database  $Db
   * @param string    $refId
   * @param string    $srcDb
   * @param integer   $nHeader
   * @param array     $resHeader
   */
  function fetchSourceHeader(&$Db,
                             &$refId,
                              $srcDb,
                             &$nHeader,
                             &$resHeader){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  NOTA_SRC='".$refId."'
                      AND STATUS='"._ACTIVE."' ";

    $Db->execFetchQuery($query,
                        $nHeader,
                        $resHeader);
  }

  /**
   * outstanding' remain to be paid
   *
   * @param Database  $Db
   * @param string    $suppCode
   * @param string    $periode
   * @param string    $refId
   * @param string    $srcDb
   * @param integer   $nRemain
   * @param array     $resRemain
   */
  function fetchOutstandingRemain(&$Db,
                                  &$suppCode,
                                  &$periode,
                                  &$refId,
                                   $srcDb,
                                  &$nRemain,
                                  &$resRemain){

    $query  = "SELECT SUM(AMOUNT) AS REMAIN
               FROM ".$srcDb."
               WHERE  REFERENCE='".$refId."'
                      AND PERIODE=".$periode." ";

    $Db->execFetchQuery($query,
                        $nRemain,
                        $result);

    $query	= "SELECT TR_DATE,
                      DUE_DATE
               FROM ".$srcDb."
               WHERE	REFERENCE='".$refId."'
                      AND PERIODE=".$periode." ";

    $Db->execFetchQuery($query,
                        $nrows,
                        $resRemain);

    $resRemain["REMAIN"] = $result["REMAIN"];

  }

  /**
   * customer outstanding
   *
   * @param Database  $Db
   * @param string    $custCode
   * @param string    $periode
   * @param string    $srcDb
   * @param integer   $nOutstanding
   * @param array     $outstanding
   */
  function fetchCustOutstanding(&$Db,
                                &$custCode,
                                &$periode,
                                 $srcDb,
                                &$nOutstanding,
                                &$outstanding){

    $outstanding = array("REFERENCE" => array(),
                         "REMAIN"    => array(),
                         "TR_DATE"   => array(),
                         "DUE_DATE"  => array());

    $query  = "SELECT DISTINCT REFERENCE
               FROM ".$srcDb."
               WHERE  PERIODE=".$periode."
                      AND CUSTOMER_CODE='".$custCode."' ";

    $Db->execFetchQuery($query,
                        $nJid,
                        $resJid);

    /**
     * foreach source JID
     * extract the remain
     */
    for($iJid = 0; $iJid < $nJid ; $iJid++){

      $this->fetchOutstandingRemain($Db,
                                    $custCode,
                                    $periode,
                                    $resJid["REFERENCE"][$iJid],
                                    $srcDb,
                                    $nRemain,
                                    $resRemain);

      if($resRemain["REMAIN"][0] > 0){

        array_push($outstanding["REFERENCE"], $resJid["REFERENCE"][$iJid]);

        array_push($outstanding["REMAIN"], $resRemain["REMAIN"][0]);

        array_push($outstanding["TR_DATE"], $resRemain["TR_DATE"][0]);

        array_push($outstanding["DUE_DATE"], $resRemain["DUE_DATE"][0]);
      }else{

        /* Do nothing */
      }
    }

    $nOutstanding = sizeof($outstanding["REFERENCE"]);
  }

  /**
   * Supplier' outstanding
   *
   * @param Database  $Db
   * @param string    $suppCode
   * @param string    $periode
   * @param string    $srcDb
   * @param integer   $nOutstanding
   * @param array     $outstanding
   */
  function fetchSuppOutstanding(&$Db,
                                &$suppCode,
                                &$periode,
                                 $srcDb,
                                &$nOutstanding,
                                &$outstanding){

    $outstanding = array("REFERENCE" => array(),
                         "REMAIN"    => array(),
                         "TR_DATE"   => array(),
                         "DUE_DATE"  => array());

    $query	= "SELECT DISTINCT REFERENCE
               FROM ".$srcDb."
               WHERE	PERIODE=".$periode."
                      AND SUPPLIER_CODE='".$suppCode."' ";

    $Db->execFetchQuery($query,
                        $nJid,
                        $resJid);

    /**
     * foreach source JID
     * extract the remain
     */
    for($iJid = 0; $iJid < $nJid ; $iJid++){

      $this->fetchOutstandingRemain($Db,
                                    $suppCode,
                                    $periode,
                                    $resJid["REFERENCE"][$iJid],
                                    $srcDb,
                                    $nRemain,
                                    $resRemain);

      if($resRemain["REMAIN"][0] > 0){

        array_push($outstanding["REFERENCE"], $resJid["REFERENCE"][$iJid]);

        array_push($outstanding["REMAIN"], $resRemain["REMAIN"][0]);

        array_push($outstanding["TR_DATE"], $resRemain["TR_DATE"][0]);

        array_push($outstanding["DUE_DATE"], $resRemain["DUE_DATE"][0]);
      }else{

        /* Do nothing */
      }
    }

    $nOutstanding = sizeof($outstanding["REFERENCE"]);
  }

  /**
   * list of cash bank tx
   *
   * @param Database  $Db
   * @param string    $srcDb
   * @param integer   $nCbTx
   * @param array     $lstCbTx
   */
  function fetchLstCbTx(&$Db,
                         $srcDb,
                        &$nCbTx,
                        &$lstCbTx){

    $query	= "SELECT *
               FROM ".$srcDb."
               ORDER BY CASH_BANK_TX_CODE DESC";

    $Db->execFetchQuery($query,
                        $nCbTx,
                        $result);

    $lstCbTx = $result["CASH_BANK_TX_NAME"];
  }
}

?>